package org.ycx.upms.dao.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.context.annotation.Primary;
import org.ycx.upms.dao.auto.SecPermissionMapper;
import org.ycx.upms.dao.model.SecPermission;

import java.util.List;

/**
 * SecPermission 自定义Mapper
 * Created by yang on 2017/6/26.
 */
@Primary
public interface ISecPermissionMapper extends SecPermissionMapper {

    @Select("SELECT DISTINCT sp.* from sec_user us join sec_user_role ur on ur.USER_ID = us.UID join sec_role_permission rp on rp.ROLE_ID = ur.ROLE_ID join sec_permission sp on sp.PERMISSION_ID = rp.PERMISSION_ID where  sp.CATEGORY <= 2 and us.uid=#{uid} and sp.system_id=#{sid}")
    @Results({
            @Result(column = "PERMISSION_ID", property = "permissionId", jdbcType = JdbcType.INTEGER, id = true),
            @Result(column = "SYSTEM_ID", property = "systemId", jdbcType = JdbcType.INTEGER),
            @Result(column = "NAME", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CATEGORY", property = "category", jdbcType = JdbcType.VARCHAR),
            @Result(column = "VALUE", property = "value", jdbcType = JdbcType.VARCHAR),
            @Result(column = "URI", property = "uri", jdbcType = JdbcType.VARCHAR),
            @Result(column = "ICON", property = "icon", jdbcType = JdbcType.VARCHAR),
            @Result(column = "STATE", property = "state", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PID", property = "pid", jdbcType = JdbcType.INTEGER),
            @Result(column = "ORDERS", property = "orders", jdbcType = JdbcType.INTEGER),
            @Result(column = "OTHER", property = "other", jdbcType = JdbcType.VARCHAR),
            @Result(column = "PAGE_ELE", property = "pageEle", jdbcType = JdbcType.VARCHAR),
            @Result(column = "CREATE_TS", property = "createTs", jdbcType = JdbcType.DATE),
            @Result(column = "CREATE_UID", property = "createUid", jdbcType = JdbcType.INTEGER),
            @Result(column = "UPDATE_TS", property = "updateTs", jdbcType = JdbcType.DATE),
            @Result(column = "UPDATE_UID", property = "updateUid", jdbcType = JdbcType.INTEGER)
    })
    List<SecPermission> selectByUserName(@Param("uid") Integer uid, @Param("sid") Integer sid);
}